package hot100.logos31To40;

import hot100.datastruct.TreeNode;

/**
 * @author logos
 * date 2025/7/13 13:11
 * @version v1.0
 * @Package hot100.logos31To40
 */
public class logos39 {

    /**
     * 39. 对称二叉树
     * https://leetcode.cn/problems/symmetric-tree/description/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public boolean isSymmetric(TreeNode root) {
            return isSameTree(root.left, root.right);
        }

        private boolean isSameTree(TreeNode p, TreeNode q) {
            if (p == null || q == null) {
                return p == q;
            }
            return p.val == q.val && isSameTree(p.left, q.right) && isSameTree(p.right, q.left);
        }
    }
}
